package com.jc.subject.domain.handler;

import com.jc.subject.common.enums.IsDeletedFlagEnum;
import com.jc.subject.common.enums.SubjectTypeFlagEnum;
import com.jc.subject.domain.convert.SubjectAnswerConverter;
import com.jc.subject.domain.entity.SubjectAnswerDO;
import com.jc.subject.domain.entity.SubjectInfoDO;
import com.jc.subject.domain.entity.SubjectOptionDO;
import com.jc.subject.infra.basic.entity.SubjectBrief;
import com.jc.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author gongjiawei
 * @Date 2024/7/9 14:32
 * @注释
 */
@Component
public class SubjectBriefHandler implements SubjectStrategy{
    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public SubjectTypeFlagEnum getcode() {
        return SubjectTypeFlagEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoDO subjectInfoDO) {

        //将信息插入单选表中 TODO

        SubjectBrief subjectBriefs = SubjectAnswerConverter.INSTANCE.convertBoToBrief(subjectInfoDO);

        subjectBriefs.setSubjectId(subjectInfoDO.getId());
        subjectBriefs.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());

        subjectBriefService.insert(subjectBriefs);
    }

    @Override
    public SubjectOptionDO query(int subjectId) {
        SubjectBrief subjectBrief = new SubjectBrief();
        subjectBrief.setSubjectId((long) subjectId);
        SubjectBrief result = subjectBriefService.queryByCondition(subjectBrief);
        SubjectOptionDO subjectOptionBO = new SubjectOptionDO();
        subjectOptionBO.setSubjectAnswer(result.getSubjectAnswer());
        return subjectOptionBO;
    }
}
